package com.eightgroups.tces.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.eightgroups.tces.entity.Indicator;
import com.eightgroups.tces.entity.Qtype;
import com.eightgroups.tces.entity.QtypeIndicator;
import com.eightgroups.tces.mapper.QtypeIndicatorMapper;
import com.eightgroups.tces.mapper.QtypeMapper;
import com.eightgroups.tces.service.IQtypeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 问卷 服务实现类
 * </p>
 *
 * @author zzc2016.cn
 * @since 2017-11-13
 */
@Service
public class QtypeServiceImpl extends ServiceImpl<QtypeMapper, Qtype> implements IQtypeService {

    @Autowired
    private QtypeMapper qtypeMapper;
    @Autowired
    private QtypeIndicatorMapper qtypeIndicatorMapper;
    @Override
    public boolean deleteQtypeByIdAndIndicator(String id) {
        // 拼接问卷表删除list
        String[] split = id.split(",");
        List<String> qtypeId = new ArrayList<>();
        for (String item:split) {
            qtypeId.add(item);
        }
        // 删除问卷表
        Integer integer = qtypeMapper.deleteBatchIds(qtypeId);

        // 删除问卷表关联表数据
        EntityWrapper<QtypeIndicator> qtypeIndicatorEntityWrapper = new EntityWrapper<>();
        qtypeIndicatorEntityWrapper.in("qid", id);
        qtypeIndicatorMapper.delete(qtypeIndicatorEntityWrapper);

        return true;
    }

}
